/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.devel.designpatterns.visitor;

import com.devel.designpatterns.composite.Composite;
import com.devel.designpatterns.composite.Leaf;

/**
 *
 * @author wm.devel
 */
public class ConsolePrintingVisitor extends Visitor {

    private int level = 0;
    
    protected void printIndent() {
        for (int i = 0; i < level; i++)
            System.out.print(" ");
    }
    
    @Override
    public void visitCompositeStart(Composite composite) {
        printIndent();
        System.out.println(composite);
        level++;
    }

    @Override
    public void visitCompositeEnd(Composite composite) {
        level--;
    }

    @Override
    public void visitLeaf(Leaf leaf) {
        printIndent();
        System.out.println(leaf);
    }
    
    
}
